// src/components/TitleListener.tsx
import { useEffect } from "react";
import { useLocation, matchRoutes } from "react-router-dom";
import { rootRouter } from "@/routers";

export const TitleListener = () => {
  const location = useLocation();

  useEffect(() => {
    const matched = matchRoutes(rootRouter, location);
    console.log("matched", matched);
    if (matched) {
      const last = matched[matched.length - 1];
      const title = last.route?.meta?.title;
      if (title) {
        document.title = title + " - 管理系统"; // 可加系统后缀
      }
    }
  }, [location]);

  return null; // 不渲染任何内容
};
